package com.wisdom.admin.service.impl;

import com.wisdom.admin.client.WxClient;
import com.wisdom.admin.service.WxService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author ming
 * @ClassName WxServiceImpl.java
 * @Description 微信相关服务端接口实现类
 * @createTime 2021年04月26日 16:26:00
 */
@Service
public class WxServiceImpl implements WxService {
    private static final Logger LOGGER = LoggerFactory.getLogger(WxServiceImpl.class);

    @Value("${wx.appid}")
    private String appid;

    @Value("${wx.secret}")
    private String secret;

    @Autowired
    WxClient wxClient;

    @Override
    public Map code2Session(String code) {
        Map wx = wxClient.code2Session(appid,secret,code);
        LOGGER.info("code2Session接口结果:{}",wx);

        if (wx.containsKey(new String("errcode")) && !wx.get(new String("errcode")).equals(0)){
            return null;
        }
        return wx;
    }
}
